
/**
 * 方法名称：属性合并
 */
const _objectAssign = function (target) {
  for (let i = 1, len = arguments.length; i < len; i++) {
    let source = arguments[i] || {};
    for (let prop in source) {
      if (source.hasOwnProperty(prop)) {
        let value = source[prop];
        if (value !== undefined) {
          target[prop] = value;
        }
      }
    }
  }
};

export function objectAssign() {
  _objectAssign.apply(undefined, arguments)
}

/**
*  函数防抖
*  @param {Function} func  包装的函数
*  @param {num} delay      延迟时间
*  @param {boolean} immediate 第一次滚动会执行两次  开始滚动和结束滚动的时候
*  @return {*}
*/

export function debounce(func, delay, immediate = false) {
  let timer,
    context = this;
  return (...args) => {
    if (immediate) {
      func.apply(context, args);
      immediate = false;
      return;
    }
    clearTimeout(timer);
    timer = setTimeout(() => {
      func.apply(context, args);
    }, delay);
  };
}
/**
*  函数防抖
*  @param {val} 
*  @return {*}
*/

export function nowSize(val, initWidth = 1920) {
  var nowClientWidth = document.documentElement.clientWidth
  return val * (nowClientWidth / initWidth);
}
